{if condition="$student_info"}
{include file="Public/header" title="编辑学生信息"/}
{else/}
{include file="Public/header" title="添加学生信息"/}
{/if}
<!-- 主容器 start -->
<div id="container" class="container-fluid">
    <div class="row-fluid">

        <!-- 左侧导航栏 start -->
        {include file="Public/sidebar"/}
        <!-- 左侧导航栏 end -->
        <!-- 主内容 start -->
        <div id="content" class="span10">
            <!-- 标题 start -->
            <div class="pageTit page-header">
                <h1>{if condition="$student_info"}编辑{else/}添加{/if}学生信息</h1>

                <div class="opt">
                    <a class="btn btn-info" href="{:U('Admin/Student/index')}">返回学生列表</a>
                </div>
            </div>
            <!-- 标题 end -->
            <!-- 内容区块 start -->
            <div class="formBox add_trees">
                <form id="addform" action="{:U('Admin/Student/save')}" method="post" enctype="multipart/form-data">
                    <input name="Id" type="hidden" value="{$student_info.Id}"/>
                    <div class="control-group">
                        <label>学生姓名：(<font color="red">必填，至少4个最多50个汉字，不能重复</font>)</label>
                        <input type="text" name="name" value="{$student_info.name}" {empty name="student_info"}ajaxurl="{:U('admin/student/check_title')}"{/empty} datatype="*1-50" nullmsg="请填写学生姓名！"
                        errormsg="不能少于1个字符大于50个汉字"/ class="form-control js_site_descript">
                        <span class="Validform_checktip"></span>
                    </div>

                    <div class="control-group">
                        <label>性别：</label>
                        <select style="width:90px" name="sex">
                            <option value='' selected>未设置</option>
                            <option value="男" {if condition="'男' eq $student_info['sex']" }selected{/if}>男</option>
                            <option value="女" {if condition="'女' eq $student_info['sex']" }selected{/if}>女</option>
                            {/volist}
                        </select>
                    </div>

                    <div class="control-group">
                        <label>民族：</label>
                        <input type="text" name="nation" value="{$student_info.nation}" datatype="*1-10"
                               errormsg="不能少于1个字符大于10个字符" class="form-control js_site_descript"/>
                        <span class="Validform_checktip"></span>
                    </div>

                    <div class="control-group">
                        <label>出生日期：</label>
                        <input type="text" name="birthday" value="{$student_info.birthday}" datatype="*0-80" nullmsg="请填写拉丁名！"
                               errormsg="标题不能少于0个字符大于80个字符" class="form-control js_site_descript"/>
                        <span class="Validform_checktip"></span>
                    </div>
                    <div class="control-group">
                        <label>身份证号：</label>
                        <input type="text" name="number" value="{$student_info.number}" class="form-control js_site_descript"/>
                    </div>
                    <div class="control-group">
                        <label>入学时间：</label>
                        <input type="text" name="into_time" value="{$student_info.into_time}"  class="form-control js_site_descript"/>
                        <span class="Validform_checktip"></span>
                    </div>
                    <div class="control-group">
                        <label>高考分数：</label>
                        <input type="text" name="gk_score" value="{$student_info.gk_score}" class="form-control js_site_descript"/>
                        <span class="Validform_checktip"></span>
                    </div>
                    <div class="control-group">
                        <label>专业：</label>
                        <select name="major_id" class="form-control js_site_descript">
                            {$major_list = get_list('Major')}
                            {volist name="major_list" id="vo"}
                            <option class="major_option" value="{$vo.Id}" {if condition="$vo['Id'] eq $student_info['major_id']" }selected{/if}>{$vo.name}</option>
                            {/volist}
                        </select>
                        <span class="Validform_checktip"></span>
                    </div>

                    <div class="control-group">
                        <label>班级：</label>
                        <select name="class_id" class="form-control js_site_descript" id="select_class">
                            {$class_list = get_list('Class')}
                            {volist name="class_list" id="vo"}
                            <option value="{$vo.Id}" {if condition="$vo['Id'] eq $student_info['class_id']" }selected{/if}>{$vo.name}</option>
                            {/volist}
                        </select>
                        <span class="Validform_checktip"></span>
                    </div>

                    <div style="clear:both;"></div>

                    <div class="control-group">
                        <input type="submit" class="btn btn-primary Sub" value="保存"/>
                    </div>
                </form>
            </div>
            <!-- 内容区块 end -->
        </div>
    </div>
</div>
        <!-- 主内容 end -->
        <script type="text/javascript">
            $(function () {
                //提交表单合法性验证
                $("#addform").Validform({
                    tiptype: function (msg, o, cssctl) {
                        if (!o.obj.is("form")) {
                            var objtip = o.obj.siblings(".Validform_checktip");
                            cssctl(objtip, o.type);
                            objtip.text(msg);
                        }
                    },
                    beforeSubmit: function (curform) {
                        $(".tag-sure").trigger("click");
                    },
                    label: "label",
                    ajaxPost: true,
                    callback: function (data) {
                        if (data.status == "ok") {
                            alert(data.info);
                            window.location.href = "{:U('admin/student/index')}";
                        } else {
                            alert(data.info);
                        }
                    }

                });
            });
            function class_list(major_id) {
                $.ajax({
                    type: "post",
                    url: "__APP__/admin/class/class_list",
                    async: true,
                    data: {
                        id: major_id,
                    },
                    datatype: "json",
                    success: function (data) {
                        var str = "";
                        if (data.status == 0) {
                            $.each(data.data, function (index, item) {
                                str += "<option value=" + item.Id + ">" + item.name + "</option>";
                            });
                            $("#select_class").empty();
                            $("#select_class").append(str);
                        }
                        else {
                            alert(data.data);
                        }
                    },
                    error: function (data) {
                        alert("数据异常，请刷新页面");
                    }
                });
            }
            $(".major_option").click(function () {
                var major_id = $(this).val();
                class_list(major_id);
            });
        </script>
        {include file="Public/footer"/}